<%@ page import="com.cgah.Listing" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'listing.label', default: 'Listing')}"/>
    <title><g:message code="default.show.label" args="[entityName]"/></title>
</head>
<body>
<div class="nav"><span class="spacer"></span>
    %{--<span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>--}%
    <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]"/></g:link></span>
    <span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]"/></g:link></span>
</div>
<div class="body">
    <h1><g:message code="default.show.label" args="[entityName]"/></h1>
    <g:if test="${flash.message}">
        <div class="message">${flash.message}</div>
    </g:if>

%{--
            L-1: The detail page for the listing shows the name of the listing
            L-2: The detail page for the listing shows the starting bid price of the listing
            L-3: The detail page for the listing shows the most recent bid
            L-4: The detail page for the listing shows the end date/time of the listing
            L-5: The detail page for the listing optionally shows the description
            L-6: The detail page for the listing shows only the user portion of the email address of the user who
                    created the listing (e.g. "mike" if the email address is "mike@piragua.com")
            L-7: The detail page for the listing allows a new bid to be placed (unit test)
            L-8: Validation errors will be displayed on the listing detail page if an added bid does not pass
                    validation (unit test
--}%

    <div class="dialog" style="width:100%;">
        <table><tr><td>
            <table>
                <tbody>

                <tr class="prop">
                    <td valign="top" class="name"><g:message code="listing.id.label" default="Id"/></td>
                    <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "id")}</td>
                </tr>
                <tr class="prop">
                    <td valign="top" class="name"><g:message code="listing.name.label" default="Name"/></td>
                    <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "name")}</td>
                </tr>
                <tr class="prop">
                    <td valign="top" class="name"><g:message code="listing.endDateTime.label" default="End Date Time"/></td>
                    <td valign="top" class="value"><g:formatDate date="${listingInstance?.endDateTime}"/></td>
                </tr>
                <tr class="prop">
                    <td valign="top" class="name"><g:message code="listing.startingBidPrice.label" default="Starting Bid Price"/></td>
                    <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "startingBidPrice")}</td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name"><g:message code="listing.seller.label" default="Seller"/></td>
                    <td valign="top" class="value">
                        <g:link controller="customer" action="show" id="${listingInstance?.seller?.id}">
                        %{--no need to check existance of @ because it's required on data entry--}%
                            ${listingInstance?.seller?.shortName}
                        %{--${listingInstance?.seller?.encodeAsHTML()}--}%
                        </g:link>
                    </td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name"><g:message code="listing.description.label" default="Description"/></td>
                    <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "description")}</td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name"><g:message code="listing.winner.label" default="Winner"/></td>
                    <td valign="top" class="value"><g:link controller="customer" action="show" id="${listingInstance?.winner?.id}">${listingInstance?.winner?.encodeAsHTML()}</g:link></td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="latestBid"><g:message code="listing.latestBid" default="Latest Bid"/></td>
                    <td valign="top" class="value">
                        <g:if test="${!listingInstance.bids?.empty}">
                            <g:link controller="bid" action="show" id="${listingInstance.latestBid.id}">${listingInstance.latestBid?.encodeAsHTML()}</g:link>
                        </g:if>
                    </td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name"><g:message code="listing.bids.label" default="Bids"/></td>

                    <td valign="top" style="text-align: left;" class="value">
                        <ul>
                            <g:each in="${listingInstance.bids}" var="b">
                                <li><g:link controller="bid" action="show" id="${b.id}">${b?.encodeAsHTML()}</g:link></li>
                            </g:each>
                        </ul>
                    </td>

                </tr>

                </tbody>
            </table>
        </td>
            <td>
                <g:form action="addBid" controller="bid"  >
                    <g:hiddenField name="listing.id" value="${listingInstance?.id}"/>
                    <table>
                        <tbody>
                        <tr class="prop">
                            <td valign="top" class="name">
                                <label for="amount"><g:message code="bid.amount.label" default="Amount"/></label>
                            </td>
                            <td valign="top" class="value ${hasErrors(bean: bidInstance, field: 'amount', 'errors')}">
                                <g:textField name="amount" value="${fieldValue(bean: bidInstance, field: 'amount')}"/>
                            </td>
                        </tr>

                        <tr class="prop">
                            <td valign="top" class="name">
                                <label for="customer"><g:message code="bid.customer.label" default="Customer"/></label>
                            </td>
                            <td valign="top" class="value ${hasErrors(bean: bidInstance, field: 'customer', 'errors')}">
                                <g:select name="customer.id"
                                        from="${com.cgah.Customer.list()}"
                                        optionKey="id"
                                    optionValue="shortName"
                                        value="${bidInstance?.customer?.id}"/>
                            </td>
                        </tr>

                        </tbody>
                    </table>
                    <div class="buttons">
                        <span class="button">
                            <g:submitButton name="create" class="create" value="${message(code: 'default.button.newBid.label', default: 'New Bid')}"/>
                        </span>
                    </div>
                </g:form>
            </td></tr></table>
        <div class="buttons">
            <g:form>
                <g:hiddenField name="id" value="${listingInstance?.id}"/>
                <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}"/></span>
                <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');"/></span>
            </g:form>
        </div>
    </div>
</body>
</html>
